#给定一个列表classes，对classes进行操作
import math
def classes():
    classes = [
        {"name": "n_1", "age": 24, "grade": "A"},
        {"name": "n_2", "age": 23, "grade": "B"},
        {"name": "n_3", "age": 28, "grade": "A"},
        {"name": "n_4", "age": 24, "grade": "A"},
        {"name": "n_5", "age": 25, "grade": "C"},
        {"name": "n_6", "age": 21, "grade": "D"},
        {"name": "n_7", "age": 27, "grade": "A"},
    ]
    return classes

#将classes按grade从A到D进行排序
res_1=classes()
res_1.sort(key=lambda x:x["grade"])
print(res_1)

#过滤器filter筛选出grade为A的同学
res_2=classes()
filter_1=filter(lambda x:x["grade"]=="A",res_2)
print(list(filter_1))

#通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)
res_3=classes()
def add_1(i):
    i['age']+=1
    #print(i['name'],i['age'],i['grade'])
    return i
map_1=map(add_1,res_3)
print(list(map_1))

#使用递归函数重构斐波那契函数，，f(n) = f(n-1) + f(n-2),,[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
def a(n):
    if n==0:
        return 0
    if n==1:
        return 1
    if n>1:
        res=a(n-1)+a(n-2)
        return res
arr=[]
for i in range(0,10010):
    if a(i)>100:
        break
    arr.append(a(i))
print(arr)